package com.znsb.msfq.view;

import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.znsb.msfq.R;
import com.znsb.msfq.app.ZnsbApp;
import com.znsb.msfq.utils.DisplayUtil;

/**
 * @name： 孙科技
 * @phone： 13308334117
 * @createTime： 2017/2/22
 * @modifyTime： 2017/2/22
 * @explain：
 */
public class LoadingDialog extends ProgressDialog {
    private String msg;

    public LoadingDialog(Context context, String msg) {
        super(context);
        this.msg = msg;
        setCanceledOnTouchOutside(true);
    }

    private int width, height;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WindowManager manager = (WindowManager) ZnsbApp.mContext.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics dm = new DisplayMetrics();
        manager.getDefaultDisplay().getMetrics(dm);
        width = dm.widthPixels;
        height = dm.heightPixels;
        initView();
    }

    private void initView() {
        setContentView(R.layout.loading);
        RelativeLayout layout = (RelativeLayout) findViewById(R.id.layout);
        TextView content = (TextView) findViewById(R.id.loading_tv);
        ImageView loading = (ImageView) findViewById(R.id.loading_img);
        layout.setAlpha(0.1f);
        final AnimationDrawable animationDrawable = (AnimationDrawable) loading.getDrawable();
        loading.post(new Runnable() {
            @Override
            public void run() {
                animationDrawable.start();
            }
        });
        content.setText(msg);
//        ViewGroup.LayoutParams p = layout.getLayoutParams();
//        p.width = DisplayUtil.dip2px(width);
//        p.height = DisplayUtil.dip2px(height);
//        layout.setLayoutParams(p);
    }

}
